import axios from "axios";
let { dataUrl } = require("./env");
export default async function (url, type = "GET", data = "") {
  if (type === "GET") {
    if (data) {
      return await axios.get(dataUrl + url);
    } else {
      for (var key in data) {
        if (url.indexOf(key) !== -1) {
          url = url + "&" + key + "=" + data[key];
        } else {
          url = url + "?" + key + "=" + data[key];
        }
      }
      return await axios.get(dataUrl + url);
    }
  } else if (type === "POST") {
    return await axios.post(dataUrl + url, data);
  }
}
